package com.uyayo.framework.message.enums;

/**
 * 公共返回结果枚举
 * Created by Administrator on 2018/5/6.
 */
public enum ResultMsgEnum {
    INTERNAL_SERVER_ERROR(500,"internal.server.error","Internal Server Error!","网络服务器错误！"),

    SAVE_SUCCESS(2001,"save.success","Save Success!","保存成功！"),
    SAVE_FAIL(5001,"save.fail","Save Fail!","保存失败！"),

    UPDATE_SUCCESS(2002,"update.success","Update Success!","修改成功！"),
    UPDATE_FAIL(5002,"update.fail","Update Error!","修改失败！"),

    EDIT_SUCCESS(2003,"edit.success","Edit Success!","编辑成功！"),
    EDIT_FAIL(5003,"edit.fail","Edit Error!","编辑失败！"),

    DELETE_SUCCESS(2004,"delete.success","Delete Success!","删除成功！"),
    DELETE_FAIL(5004,"delete.fail","Delete Error!","删除失败！"),

    INIT_SUCCESS(2005,"init.success","Init Success!","初始化成功！"),
    INIT_FAIL(5005,"init.fail","Init Fail!","初始化失败！"),

    PARAMETER_ERROR(5005,"parameter.error","Parameter Error!","参数错误！"),

    CODE_MULTIPLE(5006,"code.multiple.error","Code multiple error!","编码重复！"),
    EMAIL_MULTIPLE(5007,"email.multiple","Email multiple!","邮箱重复！"),
    PHONE_MULTIPLE(5008,"phone.multiple","Phone multiple!","手机号码重复！"),
    CAPTCHA_ERROR(5009,"captcha.error","Captcha error!","验证码错误！"),
    CAPTCHA_TIMEOUT(5010,"captcha.timeout","Captcha timeout!","验证码超时！"),
    USERNAME_PASSWORD_ERROR(5011,"username.password.error","Username or password incorrect!","用户名或密码不正确！"),
    LOGIN_FAIL(5012,"login.fail","Login failed. Please verify login information!","登录失败，请核实登录信息！"),
    LOGIN_SUCCESS(2012,"login.success","Login Success!","登录成功！"),
    AUTH_FAIL(5013,"authentication.fail","Authentication failed. Please verify login information!","认证失败，请核实登录信息！"),


    USER_NOT_EXIST(5020,"user.not.exist","User Not Exist!","该用户不存在！"),
    USER_EXIST(5021,"user.exist","User Exist!","该用户已存在！"),

    PARENT_NOT_FOUND(5030,"parent.not.found","Parent not found!","上级不存在！"),
    PARENT_SELF_ERROR(5031,"parent.self.error","The parent can't be himself!","上级不能是自己！");




    private final int code;

    private final String key;
    private final String message_en;
    private final String message_zh_CN;

    ResultMsgEnum(int code, String key,String message_en,String message_zh_CN) {
        this.code = code;
        this.key = key;
        this.message_en = message_en;
        this.message_zh_CN = message_zh_CN;
    }


    /**
     * Return the integer value of this status code.
     */
    public int code() {
        return this.code;
    }

    /**
     * Return the key of this status code.
     */
    public String getKey() {
        return this.key;
    }

    /**
     * Return the reason phrase of this status code.
     */
    public String getMessage_en() {
        return this.message_en;
    }

    /**
     * Return the reason phrase of this status code.
     */
    public String getMessage_zh_CN() {
        return this.message_zh_CN;
    }

    /**
     * Return a string representation of this status code.
     */
    @Override
    public String toString() {
        return Integer.toString(this.code);
    }


    /**
     * Return the enum constant of this type with the specified numeric value.
     * @param statusCode the numeric value of the enum to be returned
     * @return the enum constant with the specified numeric value
     * @throws IllegalArgumentException if this enum has no constant for the specified numeric value
     */
    public static ResultMsgEnum valueOf(int statusCode) {
        for (ResultMsgEnum status : values()) {
            if (status.code == statusCode) {
                return status;
            }
        }
        throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
    }
}
